package com.lyf.Controller;

import com.lyf.Entity.User;
import com.lyf.Server.UserServer;
import com.lyf.util.RespBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class UserController {
    @Autowired
    private UserServer userServer;
    private Logger logger = LoggerFactory.getLogger(UserController.class);

    @GetMapping("home")
    public String home(){
        return "Home";
    }

    @PostMapping("/user")
    @ResponseBody
    public RespBean user(){
        try {
            List<User> userList = userServer.UserList();
            return RespBean.ok("查询成功",userList);
        }catch (Exception ex){
            logger.error(ex.getMessage());
            return RespBean.error("查询失败");
        }
    }
}
